package com.pdg.android.common;

public abstract class State<S extends GameDataBase<U>,T extends StateMachine<S,T,U>,U> {
	private S data;
	private T machine;
	private U id;
	private boolean initialized = false;
	public State(S theData,T theMachine,U theId){
		setData(theData);
		setMachine(theMachine);
		setId(theId);
	}
	private void setData(S theData) {
		data = theData;
	}
	private void setId(U theId) {
		id = theId;
	}
	private void setMachine(T theMachine) {
		machine = theMachine;
	}
	public T getMachine(){
		return machine;
	}
	public U getId(){
		return id;
	}
	public S getData(){
		return data;
	}
	public void enter(){
		if(!isInitialized()){
			onInitialize();
		}
		onEnter();
	}
	private boolean isInitialized() {
		return initialized;
	}
	protected abstract void onInitialize();
	protected abstract void onEnter();
	public void leave(){
		onLeave();
	}
	protected abstract void onLeave();
	public void cleanUp(){
		onCleanUp();
	}
	protected abstract void onCleanUp();
	public void buttonPressed(int theButtonId){
		onButtonPressed(theButtonId);
	}
	protected abstract void onButtonPressed(int theButtonId);
}
